package com.SmileBreaker;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Vibrator;

public class ImageButton {
	public final static int NOTIFICATION = 0;
	public final static int MUTE = 1;
	
	private static Vibrator vibe;
	private int pX, pY, Width, Height;
	private Bitmap btnImage;
	
	public ImageButton(int pX, int pY, int Width, int Height, Bitmap btnImage) {
		this.pX = pX;
		this.pY = pY;
		this.Width = Width;
		this.Height = Height;
		this.btnImage = btnImage;
	}
	
	public void Draw(Canvas canvas) {
		btnImage = Bitmap.createScaledBitmap(btnImage, Width, Height, false);
		canvas.drawBitmap(btnImage, pX, pY, null);
	}
	
	public void DrawTranslucent(Canvas canvas, int level) {
		btnImage = Bitmap.createScaledBitmap(btnImage, Width, Height, false);
		Paint paint = new Paint();
		paint.setAlpha(level);
		canvas.drawBitmap(btnImage, pX, pY, paint);
	}
	
	public boolean IsClicked(float InputX, float InputY) {
		int pX = (int)(this.pX * DisplayInfo.displayRatio) + (int)DisplayInfo.startPaintPoint.getX();
		int pY = (int)(this.pY * DisplayInfo.displayRatio) + (int)DisplayInfo.startPaintPoint.getY();
		int Width = (int)(this.Width * DisplayInfo.displayRatio);
		int Height = (int)(this.Height * DisplayInfo.displayRatio);
		
		if(InputX >= pX && InputX <= pX+Width && InputY >= pY && InputY <= pY+Height){
			SoundManager.play(SoundManager.MENU);
			vibe.vibrate(80);
			return true;
		}
        else
        	return false;
	}
	
	public boolean IsClicked(float InputX, float InputY, int type) {
		int pX = (int)(this.pX * DisplayInfo.displayRatio) + (int)DisplayInfo.startPaintPoint.getX();
		int pY = (int)(this.pY * DisplayInfo.displayRatio) + (int)DisplayInfo.startPaintPoint.getY();
		int Width = (int)(this.Width * DisplayInfo.displayRatio);
		int Height = (int)(this.Height * DisplayInfo.displayRatio);
				
		if(InputX >= pX && InputX <= pX+Width && InputY >= pY && InputY <= pY+Height) {
			if(type == NOTIFICATION) {
				SoundManager.play(SoundManager.MENU);
				vibe.vibrate(80);
			}
			return true;
		}
        else
        	return false;
	}
	
	public static void setContext(Vibrator vibe) {	ImageButton.vibe = vibe;	}
	public Bitmap getBtnImage() {	return btnImage;	}
	public void setBtnImage(Bitmap btnImage) {	this.btnImage = btnImage;	}
}
